package com.app.web.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBConn {

	private String sDBDriver;
	private String sConnStr;
	private Connection conn;
	private ResultSet rs;
	Statement stmt;

	public DBConn() {
		sDBDriver = "com.mysql.jdbc.Driver"; // Mysql数据库的驱动程序，连接foreigntrade数据库
		sConnStr = "jdbc:mysql://localhost/utils?user=root&password=123456";
		conn = null;
		rs = null;
		try {
			Class.forName(sDBDriver);						// 加载驱动程序
			conn = DriverManager.getConnection(sConnStr);   // 建立Connection连接
			stmt = conn.createStatement(); 					// 创建语句对象

			System.out.println("数据库连接成功！");

		} catch (SQLException sqlexception) {
			System.out.println("数据库连接发生异常！");
		} catch (ClassNotFoundException e) {
			System.out.println(e.getMessage());
			System.out.println("数据库连接失败！");
		}
	}

	public ResultSet executeQuery(String sql) {
		rs = null;
		try {
			rs = stmt.executeQuery(sql);
		} catch (SQLException sqlexception) {
			System.err.println("aq.executeQuery:" + sqlexception.getMessage());
		}
		return rs;
	}
}
